<?php

namespace App\Enums;

use App\Traits\EnumTrait;

class UpgradeTypeEnum
{
    use EnumTrait;

    const MANDATORY = ['type' => 'mandatory', 'text' => "强制升级"];
    const RECOMMENDED = ['type' => 'recommended', 'text' => "推荐升级"];

    public static function getEnumByType($type)
    {
        foreach (self::getConstants() as $constant) {
            if ($constant['type'] == $type) {
                return $constant;
            }
        }
        return null;
    }

    public static function getType($data)
    {
        return $data['type'];
    }

    public static function getText($data)
    {
        return $data['text'] ?? '';
    }

    public static function getTypeToText()
    {
        return array_column(self::getConstants(), 'text', 'type');
    }

    public static function getTextByType($type)
    {
        return self::getText(self::getEnumByType($type));
    }
}
